/*
 * Copyright (C) 2025 Tsingteng MicroSystem
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef _HCI_DEFS_H_
#define _HCI_DEFS_H_

// 需要链式的时候置0，默认置1
#define HCI_HCP_CHAINING_BIT                (0x1 << 7)

#define HCI_HCP_TYPE_MASK                   (0xC0)
#define HCI_HCP_TYPE_OFFSET                 (6)
#define HCI_HCP_TYPE_CMD                    (0x00)
#define HCI_HCP_TYPE_EVENT                  (0x01)
#define HCI_HCP_TYPE_RSP                    (0x02)

#define HCI_INS_MASK                        (0x3F)
#define HCI_INS_ANY_SET_PARAM               (0x01)
#define HCI_INS_ANY_GET_PARAM               (0x02)
#define HCI_INS_ANY_OPEN_PIPE               (0x03)
#define HCI_INS_ANY_CLOSE_PIPE              (0x04)

#define HCI_INS_ADM_CREATE_PIPE             (0x10)
#define HCI_INS_ADM_DELETE_PIPE             (0x11)
#define HCI_INS_ADM_NOTIFY_PIPE_CREATED     (0x12)
#define HCI_INS_ADM_NOTIFY_PIPE_DELETED     (0x13)
#define HCI_INS_ADM_CLEAR_ALL_PIPE          (0x14)
#define HCI_INS_ADM_NOTIFY_ALL_PIPE_CLEARED (0x15)

#define HCI_RSP_MASK                        HCI_INS_MASK
#define HCI_RSP_ANY_OK                      (0x00)
#define HCI_RSP_ANY_E_NOT_CONNECTED         (0x01)
#define HCI_RSP_ANY_E_CMD_PAR_UNKNOWN       (0x02)
#define HCI_RSP_ANY_E_NOK                   (0x03)
#define HCI_RSP_ANY_E_NO_PIPES_AVAILABLE    (0x04)
#define HCI_RSP_ANY_E_REG_PAR_UNKNOWN       (0x05)
#define HCI_RSP_ANY_E_PIPE_NOT_OPENED       (0x06)
#define HCI_RSP_ANY_E_CMD_NOT_SUPPORT       (0x07)
#define HCI_RSP_ANY_E_INHIBITED             (0x08)
#define HCI_RSP_ANY_E_TIMEOUT               (0x09)
#define HCI_RSP_ANY_E_REG_ACCESS_DENIED     (0x0A)
#define HCI_RSP_ANY_E_PIPE_ACCESS_DENIED    (0x0B)

#define HCI_EVT_HCI_END_OF_OPERATION        (0x01)
#define HCI_EVT_POST_DATA                   (0x02)
#define HCI_EVT_HOT_PLUG                    (0x03)
#define HCI_EVT_TERMINAL_HOST_REQUEST       (0x04)
#define HCI_EVT_TERMINAL_HOST_INFORMATION   (0x05)
// ETSI_TS_102_622 11.2.2.0
#define HCI_EVT_CONNECTIVITY                (0x10)
#define HCI_EVT_TRANSACTION                 (0x12)
#define HCI_EVT_OPERATION_ENDED             (0x13)
#define HCI_EVT_MH_NOTIFICATION             (0x20)
// ETSI_TS_102_622 12.2.2.0 APDU gate支持的event
#define HCI_EVT_C_APDU                      (0x10)
#define HCI_EVT_ABORT                       (0x11)
#define HCI_EVT_END_OF_APDU_TRANSFER        (0x21)
// ETSI_TS_102_622 12.3.2.0 APDU application gate支持的event
#define HCI_EVT_R_APDU                      (0x10)
#define HCI_EVT_WTX                         (0x11)
#define HCI_EVT_ATR                         (0x12)

// gates
#define HCI_GATE_APP_APDU                   (0x11)
#define HCI_GATE_APDU                       (0x30)
#define HCI_GATE_CONNECTIVITY               (0x41)

// pipes
#define HCI_PIPE_MASK                       (0x7F)
#define HCI_DYNAMIC_PIPE_START              (0x02)
#define HCI_STATIC_PIPE_LINK_MANAGE         (0x00)
#define HCI_STATIC_PIPE_ADMIN               (0x01)
#define HCI_DYNAMIC_PIPE_APDU               (0x19)
#define HCI_DYNAMIC_PIPE_ESE_CONNECTIVITY   (0x16)
#define HCI_DYNAMIC_PIPE_SIM1_CONNECTIVITY  (0x0A)
#define HCI_DYNAMIC_PIPE_SIM2_CONNECTIVITY  (0x23)

// hosts
#define HCI_HOST_ID_DH                      (0x01)
#define HCI_HOST_ID_ESE                     (0xC0)
#define HCI_HOST_ID_SIM1                    (0x80)
#define HCI_HOST_ID_SIM2                    (0x81)

// gate registry
#define HCI_REGISTRY_SESSION_ID             (0x01)
#define HCI_REGISTRY_SESSION_ID_LEN         (8)
#define HCI_REGISTRY_MAX_PIPE               (0x02)
#define HCI_REGISTRY_MAX_PIPE_LEN           (1)
#define HCI_REGISTRY_WHITELIST              (0x03)
#define HCI_REGISTRY_HOST_LIST              (0x04)
// 以下属性在Rel-11及以下版本不可用
#define HCI_REGISTRY_HOST_ID                (0x05)
#define HCI_REGISTRY_HOST_ID_LEN            (1)
#define HCI_REGISTRY_HOST_TYPE              (0x06)
#define HCI_REGISTRY_HOST_TYPE_LEN          (2)
#define HCI_REGISTRY_HOST_TYPE_LIST         (0x07)
// 以下属性在Rel-12及以下版本不可用
#define HCI_REGISTRY_MANAGING_HOST_ID       (0x08)
#define HCI_REGISTRY_MH_CAPABILITY          (0x09)
#define HCI_REGISTRY_MH_CAPABILITY_LEN      (1)
#define HCI_REGISTRY_MH_AVALIABLITY_STATE   (0x0A)
#define HCI_REGISTRY_MH_AVALIABLITY_STATE_LEN (1)

// tag定义
#define HCI_EVT_TRANSACTION_AID_TAG         (0x81)
#define HCI_EVT_TRANSACTION_PARAM_TAG       (0x82)

#endif
